package app.beit.finportal.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import app.beit.finportal.service.DocumentsService;
import app.beit.finportal.service.NewsService;
import app.beit.finportal.service.RelativeWebProgramsService;
import app.beit.finportal.service.SlidesService;
import app.beit.finportal.service.WebboardService;
import app.beit.finportal.utils.constr.RelativeWebProgramsConstr;
import app.beit.finportal.utils.constr.SessionConstr;

@Controller
@RequestMapping("/")
public class MainController extends BaseController {


	@Autowired
	private NewsService newsService;
	
	@Autowired
	private SlidesService slidesService;
	
	@Autowired
	private RelativeWebProgramsService relativeWebProgramsService;
	
	@Autowired
	private WebboardService webboardService;
	
	@Autowired
	private DocumentsService documentsService;
	
	@RequestMapping("")
	public String index(final HttpServletRequest request) throws Exception{
		super.startProcess(request);
		try{
			request.setAttribute(SessionConstr.ACTIVE_PAGE, "home");

			request.setAttribute("slidepicture", this.slidesService.getAll());
			request.setAttribute("lastestNews", this.newsService.getAllLastedDate());
			
			request.setAttribute("lastestPrograms", this.relativeWebProgramsService.getAllByTypesLastestDate(RelativeWebProgramsConstr.TYPE_PROGRAM));
			request.setAttribute("lastestWebs", this.relativeWebProgramsService.getAllByTypesLastestDate(RelativeWebProgramsConstr.TYPE_WEB));
			
			request.setAttribute(SessionConstr.WEBBOARD_ALL_DATA, this.webboardService.getAllPostAtMainPage());
			
			request.setAttribute("lastestDownloads", this.documentsService.getAllLastestDate());
		}catch(Exception e){
			e.printStackTrace();
		}
		return "main";
	}
	
}
